home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / UDragDropBehavior.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  5.0 KB  |  174 lines  |  [TEXT/MPS ]

  1. // UDragDropBehavior.cp
  2. // Copyright © 1994-96 by Apple Computer, Inc. All rights reserved.
  3.  
  4. #ifndef __UDRAGDROPBEHAVIOR__
  5. #include "UDragDropBehavior.h"
  6. #endif
  7.  
  8. // MacApp
  9.  
  10. #ifndef __UCOREGLOBALS__
  11. #include "UCoreGlobals.h"
  12. #endif
  13.  
  14. #ifndef __UMACAPPGLOBALS__
  15. #include "UMacAppGlobals.h"
  16. #endif
  17.  
  18. #ifndef __USTREAM__
  19. #include "UStream.h"
  20. #endif
  21.  
  22. #ifndef __UVIEW__
  23. #include "UView.h"
  24. #endif
  25.  
  26. //========================================================================================
  27. // GLOBAL Procedures
  28. //========================================================================================
  29. #undef Inherited
  30.  
  31. //========================================================================================
  32. // CLASS TDragDropBehavior
  33. //========================================================================================
  34. #undef Inherited
  35. #define Inherited TBehavior
  36.  
  37. #pragma segment MADragRes
  38. MA_DEFINE_CLASS_M1(TDragDropBehavior, Inherited);
  39.  
  40. //----------------------------------------------------------------------------------------
  41. // TDragDropBehavior constructor
  42. //----------------------------------------------------------------------------------------
  43. #pragma segment MADragNonRes
  44.  
  45. TDragDropBehavior::TDragDropBehavior(void)
  46. {
  47.     fDraggable = FALSE;
  48.     fDroppable = FALSE;
  49.     fDragMoveDeterminer = kNeverMove;
  50.     fDragMoveFamily = kNoIdentifier;
  51. } // TDragDropBehavior
  52.  
  53. //----------------------------------------------------------------------------------------
  54. // TDragDropBehavior destructor
  55. //----------------------------------------------------------------------------------------
  56. #pragma segment MADestructorRes
  57.  
  58. TDragDropBehavior::~TDragDropBehavior()
  59. {
  60. }
  61.  
  62. //----------------------------------------------------------------------------------------
  63. // TDragDropBehavior::IDragDropBehavior 
  64. //----------------------------------------------------------------------------------------
  65. #pragma segment MAOpen
  66.  
  67. void TDragDropBehavior::IDragDropBehavior(     IDType itsIdentifier, 
  68.                                             Boolean draggable, 
  69.                                             Boolean droppable,
  70.                                             short    dragMoveDeterminer,
  71.                                             IDType    dragMoveFamily)
  72. {
  73.     this->IBehavior(itsIdentifier);
  74.     
  75.     fDraggable = draggable;
  76.     fDroppable = droppable;
  77.     
  78.     fDragMoveDeterminer = dragMoveDeterminer;
  79.     fDragMoveFamily = dragMoveFamily;
  80. } // TDragDropBehavior::IDragBehavior
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // TDragDropBehavior::ReadFrom 
  84. //----------------------------------------------------------------------------------------
  85. #pragma segment MAReadResource
  86.  
  87. void TDragDropBehavior::ReadFrom(TStream* aStream)
  88. {
  89.     Inherited::ReadFrom(aStream);
  90.  
  91.     fDraggable = aStream->ReadBoolean();
  92.     fDroppable = aStream->ReadBoolean();
  93.     fDragMoveDeterminer = aStream->ReadInteger();
  94.     fDragMoveFamily = aStream->ReadIDType();
  95. } // TDragDropBehavior::ReadFrom
  96.  
  97.  
  98. //----------------------------------------------------------------------------------------
  99. // TDragDropBehavior::WriteTo
  100. //----------------------------------------------------------------------------------------
  101. #pragma segment MAWriteResource
  102.  
  103. void TDragDropBehavior::WriteTo(TStream* aStream)
  104. {
  105.     Inherited::WriteTo(aStream);
  106.     
  107. #if qDrag
  108.     // read drag data out of the owner, since the values in the behavior may not be
  109.     // current
  110.     {
  111.         TView *ownerView = (TView *)fOwner;
  112.         
  113.         fDraggable = ownerView->GetDraggable();
  114.         fDroppable = ownerView->GetDroppable();
  115.         fDragMoveDeterminer = ownerView->GetDragMoveDeterminer();
  116.         fDragMoveFamily = ownerView->GetDragMoveFamily();
  117.     }
  118. #endif // qDrag
  119.  
  120.     aStream->WriteBoolean(fDraggable);
  121.     aStream->WriteBoolean(fDroppable);
  122.     aStream->WriteInteger(fDragMoveDeterminer);
  123.     aStream->WriteIDType(fDragMoveFamily);
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. // TDragDropBehavior::SetOwner
  128. //----------------------------------------------------------------------------------------
  129. #pragma segment MAOpen
  130.  
  131. void TDragDropBehavior::SetOwner(TEventHandler* itsOwner)
  132. {
  133.     Inherited::SetOwner(itsOwner);
  134.     
  135. #if qDrag
  136. #if qDebug
  137.     // verify that the owner is a TView
  138.     
  139.     if (itsOwner && !itsOwner->DescendsFrom(TView::GetClassDescStatic()))
  140.     {
  141.         ProgramBreak("###A TDragDropBehavior is attached to a non-view object");
  142.         return;
  143.     }
  144. #endif // qDebug
  145.  
  146.     // set data in the owner view
  147.     if (itsOwner)
  148.     {
  149.         TView *ownerView = (TView *)itsOwner;
  150.         
  151.         ownerView->SetDraggable(fDraggable);
  152.         ownerView->SetDroppable(fDroppable);
  153.         ownerView->SetDragMoveDeterminer(fDragMoveDeterminer);
  154.         ownerView->SetDragMoveFamily(fDragMoveFamily);
  155.     }
  156. #endif // qDrag
  157.  
  158. } // TDragDropBehavior::SetOwner
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // TDragDropBehavior::GetStandardSignature:
  162. //----------------------------------------------------------------------------------------
  163. #pragma segment MAWriteResource
  164.  
  165. IDType TDragDropBehavior::GetStandardSignature()
  166. {
  167.     return kDragDropBehavior;
  168. } // TDragDropBehavior::GetStandardSignature
  169.  
  170. //----------------------------------------------------------------------------------------
  171. // End of UDragDropBehavior.cp
  172.  
  173. #pragma segment Inline
  174.